package edu.kaist.cs408.pof.backend.service;

import edu.kaist.cs408.pof.backend.dao.DishDaoImpl;
import edu.kaist.cs408.pof.backend.dao.RestaurantDaoImpl;
import edu.kaist.cs408.pof.backend.dao.TalkDaoImpl;
import edu.kaist.cs408.pof.backend.dao.UserDaoImpl;
import edu.kaist.cs408.pof.common.model.*;
import edu.kaist.cs408.pof.common.service.TestSvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import java.util.List;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: duyleekun
 * Date: 5/10/12
 * Time: 1:00 AM
 * To change this template use File | Settings | File Templates.
 */
@Configurable
public class TestSvcImpl implements TestSvc {

	@Autowired(required = true)
	RestaurantDaoImpl restaurantDao;

	@Autowired(required = true)
	UserDaoImpl userDao;

	@Autowired(required = true)
	DishDaoImpl dishDao;

	@Autowired(required = true)
	TalkDaoImpl talkDao;

	@Override
	public RestaurantOwnerVo echo() {
		RestaurantOwnerVo newOwner = userDao.createRestaurantOwner(new RestaurantOwnerVo("username " + UUID.randomUUID(), "Super Owner password"));

		KaistianVo newUser = userDao.createKaistian(new KaistianVo("Super Kaistian " + UUID.randomUUID(), "Super Kaistian password"));

		double[] coor = {1, 1};
		RestaurantVo newRestaurant = new RestaurantVo("Restaurant " + UUID.randomUUID(), "010-4307-0309", "me@duy.kr", "KAIST Kusong Dong", coor);

		restaurantDao.createRestaurant(newRestaurant);
		userDao.setRestaurant(newOwner.getMid(), newRestaurant.getMid());


		for (int i = 0; i < 5; i++) {
			DishVo newDish = dishDao.createDish(new DishVo("Dish " + UUID.randomUUID(), 5000));
			restaurantDao.addDish(newRestaurant.getMid(), newDish.getMid());
			for (int j = 0; j < 3; j++) {
				TalkVo newTalkDish = talkDao.createTalk(new TalkVo("omg, this dish is super delicious" + UUID.randomUUID()));
				talkDao.setTalk(newTalkDish.getMid(), newUser.getMid(), newRestaurant.getMid(), newDish.getMid());
			}
		}

		for (int i = 0; i < 3; i++) {
			TalkVo newTalk = talkDao.createTalk(new TalkVo("omg, this restaurant is awesome " + UUID.randomUUID()));
			talkDao.setTalk(newTalk.getMid(), newUser.getMid(), newRestaurant.getMid(), null);
		}

		return userDao.findRestaurantOwner(newOwner.getUsername());
	}

	@Override
	public List<RestaurantVo> echo1() {
		return restaurantDao.getRestaurants();
	}
}
